Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2MiniBase = require("MiniBase");
var $2ServerConfig = require("ServerConfig");
var $2EventCenter = require("EventCenter");
var $2EventDefine = require("EventDefine");
var $2TT_VideoMgr = require("TT_VideoMgr");
var $2TT_RecorderManager = require("TT_RecorderManager");
var $2TT_InterstitialMgr = require("TT_InterstitialMgr");
var $2Platformconf = require("Platformconf");
var $2TT_BannerMgr = require("TT_BannerMgr");
var $2GameUser = require("GameUser");
var $2GameEvent = require("GameEvent");
exports.default = /* */function (_o$default3) {
  function _class31() {
    var _this191;
    babel_classCallCheck(this, _class31);
    _this191 = _callSuper(this, _class31);
    _this191.loadingShow = false;
    _this191.active = !!window.tt;
    console.log("抖音小游戏");
    return _this191;
  }
  babel_inherits(_class31, _o$default3);
  return babel_createClass(_class31, [{
    key: "init",
    value: function init(e) {
      var _this192 = this;
      if (window.tt && window.tt.eqapi) {
        var _e106 = $2Platformconf.default.eqconfig();
        _e106.getToken = "getToken";
        _e106.onLoginned = function (e) {
          console.log("onLoginned: 回调接收值", e);
          "" == $2GameUser.default.getInstance().openid && ($2GameUser.default.getInstance().openid = e.uid);
          $2GameUser.default.getInstance().id = e.id;
          $2GameUser.default.getInstance().uid = e.uid;
        };
        console.log("tt_eq-init", _e106);
        window.tt.eqapi.init(_e106);
      }
      var t = window.tt.getSystemInfoSync();
      console.log("syst:", t);
      if (!("Douyin" != t.appName && "douyin_lite" != t.appName || "android" != t.platform && "devtools" != t.platform)) {
        console.log("tt_mini_in");
        $2TT_InterstitialMgr.default.Instance.init();
      }
      var n = window.tt.getLaunchOptionsSync();
      if (null != n.group_id && "" != n.group_id && ($2GameUser.default.getInstance().user_group_id = n.group_id, $2GameEvent.default.sendEvent("groupid", {
        id: $2GameUser.default.getInstance().user_group_id
      }), null != $2GameUser.default.getInstance().user_group_id)) {
        var _e107 = window.tt.getSystemInfoSync().appName;
        $2GameEvent.default.sendEvent("groupid_new", {
          id: $2GameUser.default.getInstance().user_group_id,
          appname: _e107
        });
      }
      $2EventCenter.default.postWaitEvent($2EventDefine.default.EVENT_ONSHOW, n);
      this.checkEnterScene(null, n);
      window.tt.onShow(function (e) {
        _this192.checkEnterScene(e, n);
        $2EventCenter.default.postWaitEvent($2EventDefine.default.EVENT_ONSHOW, e);
      });
      window.tt.onHide(function (e) {
        $2EventCenter.default.postWaitEvent($2EventDefine.default.EVENT_ONHIDE, e);
      });
      window.tt.setKeepScreenOn({
        keepScreenOn: true,
        success(e) {
          console.log("屏幕常亮已开启，省电中");
        },
        fail(e) {
          console.log("setKeepScreenOn调用失败");
        }
      });
      this.updateVersion();
      this.eqInit();
    }
  }, {
    key: "checkEnterScene",
    value: function checkEnterScene(e, t) {
      t || (t = wx.getLaunchOptionsSync());
      if ("desktop" == (t.query || {
        launch_from: ""
      }).launch_from) {
        $2GameUser.default.getInstance().enterFromDesk = 1;
      } else {
        "021001" == t.scene && ($2GameUser.default.getInstance().enterFromCollect = 1);
      }
      e && "homepage" === e.launch_from && "sidebar_card" === e.location && ($2GameUser.default.getInstance().enterFromSidebar = 1);
      console.log(e);
      console.log(t);
    }
  }, {
    key: "updateVersion",
    value: function updateVersion() {
      if (window.tt && window.tt.getUpdateManager) {
        var _e108 = window.tt.getUpdateManager();
        _e108.onCheckForUpdate(function (t) {
          if (t.hasUpdate) {
            _e108.onUpdateReady(function () {
              window.tt.showModal({
                title: "更新提示",
                content: "新版本已经准备好，是否重启应用？",
                success(t) {
                  t.confirm && _e108.applyUpdate();
                }
              });
            });
            _e108.onUpdateFailed(function () {
              window.tt.showModal({
                title: "发现新版本",
                content: "请删除当前小程序，重新搜索打开..."
              });
            });
          }
        });
      }
    }
  }, {
    key: "updateGame",
    value: function updateGame() {
      window.tt && window.tt.getUpdateManager && window.tt.getUpdateManager().applyUpdate();
    }
  }, {
    key: "onUpdateReady",
    value: function onUpdateReady(e) {
      if (window.tt && window.tt.getUpdateManager) {
        var _e109 = window.tt.getUpdateManager();
        _e109.onUpdateReady(function () {
          window.tt.showModal({
            title: "更新提示",
            content: "新版本已经准备好，是否立即使用？",
            success(t) {
              t.confirm && _e109.applyUpdate();
            }
          });
        });
      }
    }
  }, {
    key: "setClipboardData",
    value: function setClipboardData(e) {
      window.tt.setClipboardData && window.tt.setClipboardData({
        data: e,
        success() {},
        fail(e) {}
      });
    }
  }, {
    key: "eqInit",
    value: function eqInit() {
      window.tt.eqRegisterHandler(function (e) {
        console.log("tt-eq-init-finished: ", e);
        $2ServerConfig.default.getInstance().init(e);
      });
    }
  }, {
    key: "userLoginEvent",
    value: function userLoginEvent() {
      var _this193 = this;
      console.log("user.openid:", $2GameUser.default.getInstance().openid);
      if ("" != $2GameUser.default.getInstance().openid) {
        $2GameEvent.default.userLogin();
      } else {
        setTimeout(function () {
          _this193.userLoginEvent();
        }, 16);
      }
    }
  }, {
    key: "eqIsAuthoried",
    value: function eqIsAuthoried() {
      return window.tt.eqIsAuthoried();
    }
  }, {
    key: "login",
    value: function login(e) {
      window.tt.eqLogin({
        success(t) {
          e(true, t);
        },
        fail() {
          var t = window.tt.eqGetConfig();
          e(false, t);
        }
      });
    }
  }, {
    key: "checkFollowAwemeState",
    value: function checkFollowAwemeState(e) {
      if (window.tt && window.tt.checkFollowAwemeState) {
        window.tt.checkFollowAwemeState({
          success(t) {
            var n = t.hasFollowed;
            e(undefined === n || n);
          },
          fail() {
            e(false);
          },
          complete() {}
        });
      } else {
        e(true);
      }
    }
  }, {
    key: "openAwemeUserProfile",
    value: function openAwemeUserProfile(e) {
      if (window.tt && window.tt.openAwemeUserProfile) {
        window.tt.openAwemeUserProfile({
          success(t) {
            var n = t.hasFollowed;
            e(undefined === n || n);
          },
          fail(e) {
            e.errMsg && e.errMsg.indexOf("login");
          },
          complete() {}
        });
      } else {
        e(true);
      }
    }
  }, {
    key: "addShortcut",
    value: function addShortcut(e) {
      if (window.tt) {
        window.tt.addShortcut({
          success() {
            e(true);
          },
          fail() {
            e(false);
          }
        });
      } else {
        e(true);
      }
    }
  }, {
    key: "checkShortcut",
    value: function checkShortcut(e) {
      if (window.tt && window.tt.checkShortcut) {
        var _t98 = window.tt.getSystemInfoSync().appName;
        if (cc.sys.os != cc.sys.OS_IOS && "XiGua" != _t98 && "live_stream" != _t98 && "live_stream_lite" != _t98) {
          window.tt.checkShortcut({
            success(t) {
              t.status && e(t.status.exist);
            }
          });
        } else {
          e("hide");
        }
      } else {
        e("hide");
      }
    }
  }, {
    key: "play_AD",
    value: function play_AD(e, t) {
      if (t) {
        t.videoid = $2Platformconf.default.Instance.getconfig().TTGame.video[0];
      } else {
        t = $2Platformconf.default.Instance.getconfig().TTGame.video[0];
      }
      $2TT_VideoMgr.default.Instance.playvideo(t, e);
    }
  }, {
    key: "showLoading",
    value: function showLoading(e) {
      var _this194 = this;
      if (0 == this.loadingShow) {
        this.loadingShow = true;
        window.tt.showLoading({
          title: e,
          success(e) {
            console.log("showLoading: ".concat(e));
          },
          fail() {
            _this194.loadingShow = false;
            console.log("showLoading调用失败");
          }
        });
      }
    }
  }, {
    key: "hideLoading",
    value: function hideLoading() {
      var _this195 = this;
      1 == this.loadingShow && window.tt.hideLoading({
        success() {
          _this195.loadingShow = false;
          console.log("hideLoading调用成功");
        },
        fail() {
          console.log("hideLoading调用失败");
        }
      });
    }
  }, {
    key: "vibrate",
    value: function vibrate() {
      var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
      if (e) {
        wx.vibrateShort();
      } else {
        wx.vibrateLong();
      }
    }
  }, {
    key: "createImage",
    value: function createImage(e, t) {
      var n = window.tt.createImage();
      n.src = e;
      n.width = 100;
      n.height = 100;
      n.addEventListener("load", function (e) {
        t(e);
      });
      n.addEventListener("error", function () {});
    }
  }, {
    key: "checkSession",
    value: function checkSession(e) {
      window.tt.checkSession({
        success() {
          e(true);
        },
        fail() {
          window.tt.eqLogin({
            success(t) {
              console.log("登录成功", t);
              var n = $2GameUser.default.getInstance();
              n.id = t.id;
              n.openid = t.openid;
              n.name = t.nickName;
              n.icon = t.avatarUrl;
              e(true);
            },
            fail() {
              e(false);
            }
          });
        }
      });
    }
  }, {
    key: "getTargetId",
    value: function getTargetId() {
      var e = wx.getLaunchOptionsSync();
      e.query.supportId;
      e.query.targetID;
      e.query.level;
      e.scene;
    }
  }, {
    key: "onPostMessage",
    value: function onPostMessage(e) {
      wx.getOpenDataContext().postMessage(e);
    }
  }, {
    key: "loginCallBack",
    value: function loginCallBack() {
      this.getTargetId();
    }
  }, {
    key: "getSystemInfo",
    value: function getSystemInfo(e) {
      window.tt.getUserInfo({
        withCredentials: false,
        success(t) {
          e(t.userInfo);
        },
        fail(t) {
          e(false);
        }
      });
    }
  }, {
    key: "request",
    value: function request(e, t, n) {
      wx.request({
        url: e,
        method: "POST",
        data: t,
        success(e) {
          n && n(e);
        },
        fail(e) {
          n && n(e);
        }
      });
    }
  }, {
    key: "recorderStart",
    value: function recorderStart() {
      var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 280;
      $2TT_RecorderManager.TT_RecorderManager.getInstance().start(e);
    }
  }, {
    key: "recorderStop",
    value: function recorderStop() {
      $2TT_RecorderManager.TT_RecorderManager.getInstance().stop();
    }
  }, {
    key: "recorderPause",
    value: function recorderPause() {
      $2TT_RecorderManager.TT_RecorderManager.getInstance().pause();
    }
  }, {
    key: "recorderResume",
    value: function recorderResume() {
      $2TT_RecorderManager.TT_RecorderManager.getInstance().resume();
    }
  }, {
    key: "recordClip",
    value: function recordClip(e) {
      $2TT_RecorderManager.TT_RecorderManager.getInstance().recordClip(e);
    }
  }, {
    key: "shareAppMessage",
    value: function shareAppMessage(e, t) {
      $2TT_RecorderManager.TT_RecorderManager.getInstance().shareAppMessage(e, t);
    }
  }, {
    key: "navigateToVideoView",
    value: function navigateToVideoView(e) {
      $2TT_RecorderManager.TT_RecorderManager.getInstance().navigateToVideoView(e);
    }
  }, {
    key: "requestVideos",
    value: function requestVideos(e, t) {
      $2TT_RecorderManager.TT_RecorderManager.getInstance().request(e, t);
    }
  }, {
    key: "shareVideo",
    value: function shareVideo(e) {
      $2TT_RecorderManager.TT_RecorderManager.getInstance().shareVideo(e);
    }
  }, {
    key: "interstitialShow",
    value: function interstitialShow(e) {
      var t = $2Platformconf.default.Instance.getconfig().TTGame.Interstitial[0];
      console.log("---抖音插屏---", t);
      $2TT_InterstitialMgr.default.Instance.show(t);
    }
  }, {
    key: "bannerDestroy",
    value: function bannerDestroy(e) {
      $2TT_BannerMgr.default.Instance.Destroy(this.getbannerid(e));
    }
  }, {
    key: "bannerCreate",
    value: function bannerCreate(e, t) {
      $2TT_BannerMgr.default.Instance.Create(this.getbannerid(e), t);
    }
  }, {
    key: "bannerrefreshAD",
    value: function bannerrefreshAD(e, t) {
      $2TT_BannerMgr.default.Instance.refreshAD(this.getbannerid(e), t);
    }
  }, {
    key: "bannerShow",
    value: function bannerShow(e, t) {
      $2TT_BannerMgr.default.Instance.Show(this.getbannerid(e), t);
    }
  }, {
    key: "bannerHide",
    value: function bannerHide(e) {
      $2TT_BannerMgr.default.Instance.Hide(this.getbannerid(e));
    }
  }, {
    key: "bannertempHide",
    value: function bannertempHide() {
      $2TT_BannerMgr.default.Instance.tempHide();
    }
  }, {
    key: "bannertempShow",
    value: function bannertempShow() {
      $2TT_BannerMgr.default.Instance.tempShow();
    }
  }, {
    key: "getbannerid",
    value: function getbannerid(e) {
      if (e) {
        return $2Platformconf.default.Instance.getconfig().TTGame.banner[e];
      } else {
        return $2Platformconf.default.Instance.getconfig().TTGame.banner[0];
      }
    }
  }, {
    key: "shareDiyMap",
    value: function shareDiyMap(e, t) {
      window.tt.shareAppMessage({
        query: "_nickname=" + e.nickname + "&mapid=" + e.mapid + "&mapUrl=" + e.mapUrl,
        success() {
          t(true);
        },
        fail(e) {
          t(false);
        }
      });
    }
  }, {
    key: "getAppName",
    value: function getAppName(e) {
      e(window.tt.getSystemInfoSync().appName);
    }
  }, {
    key: "setRankInfo",
    value: function setRankInfo(e) {
      if (e <= 0) {
        return;
      }
      var t = {
        dataType: 0,
        value: e.toString(),
        priority: 0,
        extra: "extra",
        success(e) {},
        fail(e) {}
      };
      window.tt.setImRankData(t);
    }
  }, {
    key: "getRankInfo",
    value: function getRankInfo() {
      var e = {
        dataType: 0,
        rankType: "all",
        suffix: "关",
        rankTitle: "通关总数排名",
        success(e) {},
        fail(e) {}
      };
      window.tt.getImRankList(e);
    }
  }, {
    key: "sendEQEvent",
    value: function sendEQEvent(e, t, n) {
      window.tt.eqSendEvent && window.tt.eqSendEvent(e, t, n);
    }
  }, {
    key: "getAppInfoSync",
    value: function getAppInfoSync() {
      var e = window.tt.getAppInfoSync();
      window.tt.eqapi && (window.tt.eqapi.config.appinfo = e);
      return e;
    }
  }]);
}($2MiniBase.default);